package com.zjw.zy.utils

import android.app.Activity
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import com.zjw.zy.ext.value
import com.zjw.zy.smi.JustWithIt

object DialogUtils {

    fun alertConfirm(
        title: String = "",
        message: String = "",
        activity: Activity = AppUtils.getCurrentActivity(),
        autoCancel: Boolean = true,
        call: JustWithIt<Boolean>? = null
    ) {
        AlertDialog.Builder(activity)
            .setTitle(title)
            .setMessage(message)
            .setCancelable(autoCancel)
            .setPositiveButton("确定") { dialog, witch ->
                call?.onWith(true)
            }.setNegativeButton("取消") { dialog, witch ->
                call?.onWith(false)
            }.show()
    }


    fun alertInput(
        title: String = "",
        text: String = "",
        activity: Activity = AppUtils.getCurrentActivity(),
        autoCancel: Boolean = true,
        call: JustWithIt<String>? = null
    ) {
        val editText = EditText(activity)
        editText.setText(text)
        AlertDialog.Builder(AppUtils.getCurrentActivity())
            .setTitle(title)
            .setCancelable(autoCancel)
            .setView(editText)
            .setPositiveButton("确定") { dialog, witch ->
                call?.onWith(editText.value())
            }.setNegativeButton("取消") { dialog, witch ->
            }.show()
    }
}